<? $first_poll_id = 0;?>
<div id="heading">
    <div id="headinginner">
        <h1><span>Ankete</span></h1>
        <div id="heading-nav">
            <ul class="navcontrol">
                <li><a class="side-left side-right linklabel custom-styles" href="javascript:void(0)">Podešeni stilovi anketa</a></li>
            </ul>
        </div>
        <p class="clear"></p>
    </div>                          
</div>                              
<div id="stage-inner">
    <?
        if(isset($_POST['info'])){
        ?>
        <div class="info" style="min-height: 30px;">
            <p><?=$_POST['message']?></p>
            <a class="button dismiss javascript" href="javascript:void(0)" style="display: inline;">Zatvori</a>
            <p class="clear"></p>
        </div>
        <p class="clear"></p>
        <script>
            $('.dismiss').bind('click', function(){
                $('.info').fadeOut('slow');
            })
        </script>
        <?    
        }
    ?>
    <div class="box nopadding" style="margin-top: 15px; border: 1px solid #D2D0D0; background: #FFFFFF;">
        <div class="qoptions qoptionssmlpadding"> 
            <div class="right">
                <a class="button new-item" href="<?=base_url()?>anketa/uredi_anketu">Kreirajte novu anketu</a>
            </div>
            <p class="clear"></p>
        </div>
        <table cellspacing="0" cellpadding="0" class="folder-table">
            <tbody>
                <tr>
                    <td style="border-right: 1px solid #CCCBCA;">
                        <div style="height: 520px;">
                            <div id="ankete" class="" role="tablist">
                                <div class="ankete-content-list" style="height: 497px; overflow: auto;" role="tabpanel">
                                    <? 
                                        if(count($ankete)==0){?>
                                        <div class="no-votes">Još uvek niste kreirali nijednu anketu. Kada to uradite, moćićete da ih vidite ovde!</div>
                                        <?}else{?>
                                        <ul> 
                                            <? $selected=TRUE; foreach($ankete as $anketa){ ?>
                                                <li id="<?=$anketa->id;?>" <? if($selected){ echo 'class="selected"'; $selected=false; $first_poll_id = $anketa->id; } ?>>
                                                    <a href="javascript:void(0)" class="edit">
                                                        <span class="item-status <? if($anketa->status==2){echo 'closed';}else{echo 'open';}?>"></span>
                                                        <?=$anketa->question; ?>
                                                    </a>
                                                    <p class="clear"></p>
                                                </li> 
                                                <? } ?>
                                        </ul>
                                        <? } ?>     
                                </div>
                            </div>
                        </div>
                    </td>
                    <td id="minireport">

                    </td>
                </tr> 
            </tbody>
        </table>
    </div>  
</div>
<div id="custom-styles-modal" style="display: none;">
    <div id="custom-styles-holder" class="dialog">
        <div class="body">
            <div class="title-with-controls">
                <div class="title">Pregled podešenih stilova</div>

                <ul class="navcontrol">
                    <li><a class="single linkadd" href="<?=base_url()?>style/pogledaj_uredi_stil">Kreirajte novi stil</a></li>
                </ul>
                <p class="clear"></p>
            </div>

            <div class="list">
                <table cellspacing="0">
                    <tbody>
                        <? 
                            if(count($styles_custom)==0){?>
                            <div class="no-votes">Još uvek niste kreirali nijedan stil za anketu. Kada to uradite, moćićete da ih vidite ovde!</div>
                            <?}else{ foreach($styles_custom as $style){ ?>                  
                                <tr class="item">
                                    <td class="link">
                                        <a href="<?=base_url()?>style/pogledaj_uredi_stil/<?=$style->id;?>" class="link-edit"><?=$style->name;?></a>
                                        <!--<span>created February 16th, 2011</span>-->
                                    </td>
                                    <td style="width: 200px;" class="options">
                                        <ul class="navcontrol right">
                                            <li><a class="side-left link-edit" href="<?=base_url()?>style/pogledaj_uredi_stil/<?=$style->id;?>">Uredi stil</a></li>
                                            <li class="space"></li>
                                            <li><a href="javascript:void(0)" id="<?=$style->id;?>" class="side-right link-delete-style">Obriši</a></li>
                                        </ul>
                                    </td>
                                </tr>
                                <?} }?>              
                    </tbody>
                </table>
            </div> 
        </div>
        <div class="controls">
            <div class="right">
                <a class="button custom-styles-done" href="#">Zatvori</a>
                <p class="clear"></p>
            </div>
            <p class="clear"></p>
        </div> 
    </div>
</div>
<div id="poll-status-modal" style="display: none;">
    <div id="poll-status-holder" class="dialog">
        <div class="body">
            <div class="title" id="status-title"></div>
            <div class="text">
                <p id="status-text"></p>                              
            </div>
        </div>

        <div class="controls">
            <div class="right">
                <a href="javascript:void(0)" class="plain custom-styles-done">Otkaži</a>
                <a class="button confirm-poll-status" href="javascript:void(0)" id="">Potvrdi</a>
                <p class="clear"></p>
            </div>
            <p class="clear"></p>
        </div> 
    </div>
</div>
<div id="embeded-code-modal" style="display: none;">
    <div id="embeded-code-holder" class="dialog">
        <div class="body">
            <div class="title">Embed code - iskopirajte na mjestu gdje želite prikazati anketu</div>
            <div class="text">
                <p><textarea cols="30" rows="10" id="code-in"></textarea></p>                              
            </div>
        </div>

        <div class="controls">
            <div class="right">
                <a class="button custom-styles-done" href="javascript:void(0)" id="">Uredu</a>
                <p class="clear"></p>
            </div>
            <p class="clear"></p>
        </div> 
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        function prikazi_anketu(id){
            $.ajax({
                type: 'POST',
                url: base_url+'rezultati/prikazi_rezultat',
                data:{id:id},
                dataType: 'json',
                success: function(data){
                    $('#minireport').html(data.html);
                    $('#minireport').show();            
                },
                error:function(data){alert("Error: " + data);}
            });
            return false;
        }
        $('.ankete-content-list li').live('click',function(){
            $('#minireport').hide();
            var id = this.id;
            prikazi_anketu(id);
            $('.ankete-content-list li').each(function(index, value){
                $(value).removeClass('selected');
                if(id==value.id){
                    $(value).addClass('selected');
                }
            })            
        })
        var first_id = '<?=$first_poll_id;?>';
        if(first_id!=0){
            prikazi_anketu(first_id);   
        };
    });
</script>
